/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "Thread.h"

#include <windows.h>

namespace PQCore
{
	DWORD WINAPI threadFunction(void* derivedThread)
	{
		Thread * thread = (Thread*)derivedThread;
		if( thread==NULL ){
			return 0;
		}
		thread->setState(Thread::Running);
		thread->run();//run thread
		thread->setState(Thread::Exited);
		thread->exit(0);
		

		//Thread lock
		return 0;
	}

	

	Thread::Thread() : _threadId(0),_state(Ready)
	{

	}

	Thread::~Thread()
	{
	}

	void Thread::start()
	{
		if(_state!=Ready){
			return;
		}

		//WINDOWS
		_threadHandle=::CreateThread(NULL,0,threadFunction,this,0,&_threadId);

	}

	void Thread::exit(void* retval)
	{
		//WINDOWS
		::CloseHandle( _threadHandle ) ;
	}

	void Thread::stop()
	{
	}

	void Thread::run()
	{
	}


}
